package com.sanen.flyer.factory;

import com.sanen.flyer.entity.GameBackground;
import com.sanen.flyer.tool.ImageTool;

import java.awt.image.BufferedImage;

/**
 * @author wsse
 * @date 2018-09-06 17:24
 */
public class BgFactory {
    public static BufferedImage image;
    public static final int BG_1=1;
    public static BufferedImage bg1;
    public static final int BG_2=2;
    public static BufferedImage bg2;
    public static GameBackground getBg(int type){
        switch(type){
            case BG_1:
                if(bg1==null)loadBg1();
                image=bg1;
                break;
            case BG_2:
                if(bg2==null)loadBg2();
                image=bg2;
                break;
        }
        return new GameBackground(image);
    }
    /**
     * 加载背景1图片
     */
    private static void loadBg1() {
        bg1= ImageTool.getImage("./image/bg/bg1.jpg");
    }

    /**
     * 加载背景2图片
     */
    private static void loadBg2() {
        bg2= ImageTool.getImage("./image/bg/bg2.jpg");
    }
}
